<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>ec</title>
  <!-- import CSS -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">

</div>
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
<script>
  new Vue({
    el: '#app',
    data() {
      return {}
    },
    methods: {
      getQueryVariable(paramName) {
        let query = window.location.search.substring(1);
        let vars = query.split("&");
        for (let i = 0; i < vars.length; i++) {
          let pair = vars[i].split("=");
          if (pair[0] == paramName) {
            return pair[1];
          }
        }
        return '';
      }
    },
    created() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      //url获取code
      let code = this.getQueryVariable('code');
      this.$http.get('http://127.0.0.1:9011/token/' + code
      ).then(res => {
        loading.close();
        if (res.status == '200') {
          sessionStorage.setItem('access_token', res.body.access_token);
          sessionStorage.setItem('refresh_token', res.body.refresh_token);
          // window.location = sessionStorage.getItem('visitUri');
          window.location = "http://127.0.0.1:9011";
        } else {
          console.error(res.statusText)
        }
      }).catch(res => {
        console.error(res)
      })
    }
  })
</script>
</body>
</html>